package HLLib.ui;

import HLCode.HLClass;
import HLCode.HLClassManager;
import HLCode.HLClassManager_H;
import HLCode.HLObject;
import HLLib.base.HLDictionary;
import HLLib.base.HLImageManager;
import HLLib.base.HLIntList;
import HLLib.base.HLList;
import HLLib.base.HLLoading;
import HLLib.base.HLString;
import HLLib.game.HLSpriteSeedManager;

public class HLUISeedManager extends HLList {
    public HLClass GetClass(HLClassManager classManager) {
        return classManager.GetLibClass(HLClassManager_H.CLASS_GROUP_TYPE_LIB_UI, HLClassManager_H.LIB_CLASS_UI_UISeedManager);
    }

    public int GetInt(int index) {
        return super.GetInt(index);
    }

    public void SetInt(int index, int value) {
        super.SetInt(index, value);
    }

    public boolean GetBoolean(int index) {
        return super.GetBoolean(index);
    }

    public void SetBoolean(int index, boolean value) {
        super.SetBoolean(index, value);
    }

    public HLObject GetObject(int index) {
        switch (index) {
        case 0: {
            return imageManager;
        }
        case 1: {
            return spriteSeedManager;
        }
        case 2: {
            return languageTextDictionary;
        }
        }
        return super.GetObject(index);
    }

    public void SetObject(int index, HLObject value) {
        switch (index) {
        case 0: {
            imageManager = (HLImageManager) value;
            return;
        }
        case 1: {
            spriteSeedManager = (HLSpriteSeedManager) value;
            return;
        }
        case 2: {
            languageTextDictionary = (HLDictionary) value;
            return;
        }
        }
        super.SetObject(index, value);
    }

    public HLImageManager imageManager;

    public HLSpriteSeedManager spriteSeedManager;

    public HLDictionary languageTextDictionary;

    public HLUISeedManager() {
    }

    public void Load(int type, int endProgress) {
        while (type >= items.length) {
            Add(null);
        }
        if (items[type] == null) {
            HLUISeed uiSeed = new HLUISeed(this);
            uiSeed.Load(type, true, true, endProgress);
            items[type] = uiSeed;
        } else {
            HLLoading.SetProgress(endProgress);
        }
    }

    public void LoadEX(int type, boolean needOpenImagePack, boolean needCloseImagePack, int endProgress) {
        while (type >= items.length) {
            Add(null);
        }
        if (items[type] == null) {
            HLUISeed uiSeed = new HLUISeed(this);
            uiSeed.Load(type, needOpenImagePack, needCloseImagePack, endProgress);
            items[type] = uiSeed;
        } else {
            HLLoading.SetProgress(endProgress);
        }
    }

    public void Loads(int startIndex, int endIndex, int endProgress) {
        int startProgress = HLLoading.GetProgress();
        int dProgress = endProgress - startProgress;
        for (int i = startIndex; i <= endIndex; i++) {
            LoadEX(i, true, false, startProgress + dProgress * (i - startIndex) / (endIndex - startIndex + 1));
        }
        HLLoading.SetProgress(endProgress);
        HLImageManager.CloseImagePackage();
    }

    public void LoadList(HLIntList list, int endProgress) {
        int startProgress = HLLoading.GetProgress();
        int dProgress = endProgress - startProgress;
        for (int i = 0; i < list.items.length; i++) {
            LoadEX(list.items[i], true, false, startProgress + dProgress * i / list.items.length);
        }
        HLLoading.SetProgress(endProgress);
        HLImageManager.CloseImagePackage();
    }

    public void LoadAll(int count, int endProgress) {
        int startProgress = HLLoading.GetProgress();
        int dProgress = endProgress - startProgress;
        for (int i = 0; i < count; i++) {
            LoadEX(i, true, false, startProgress + dProgress * i / count);
        }
        HLLoading.SetProgress(endProgress);
        HLImageManager.CloseImagePackage();
    }

    public void UnLoad(int type) {
        if (items[type] != null) {
            ((HLUISeed) items[type]).UnLoadImages();
            items[type] = null;
        }
    }

    public void Clear() {
        for (int i = 0; i < items.length; i++) {
            UnLoad(i);
        }
    }

    public HLObject GetItem(int index) {
        return (HLObject) items[index];
    }

    public void SetItem(int index, HLUISeed item) {
        items[index] = item;
    }

    public HLUI CreateUI(int type) {
        return new HLUI((HLUISeed) items[type]);
    }

    public HLString GetLanguageTextByScript(HLString script) {
        return HLString.GetLanguageTextByScript(languageTextDictionary, script);
    }
}
